package com.itheima.sky.dao;

import com.github.pagehelper.Page;
import com.itheima.sky.pojo.OrderDetail;
import com.itheima.sky.pojo.Orders;
import com.itheima.sky.vo.OrderDetailVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description OrderMapper
 * @Author jiangning
 * @Date 2024-06-28
 */
@Mapper
public interface OrderMapper {
    @Select("select * from orders where user_id=#{userId}")
    List<Orders> getOrdersByUserId(Long userId);

    @Select("select * from orders where user_id=#{userId}")
    Page<Orders> getOrdersByUserIdPH(Long userId);

    @Select("select * from order_detail where order_id = #{id}")
    List<OrderDetail> getOrderDetailsByOrderId(Long id);
    @Select("select * from order_detail where order_id = #{id}")
    List<OrderDetailVO> getOrderDetailsByOrderIdVO(Long id);

    @Select("<script>" +
            "SELECT * FROM orders " +
            "WHERE 1=1 " +
            "<if test='number != null and number != \"\"'>AND LOWER(number) LIKE concat(LOWER(#{number}), '%')</if> " +
            "<if test='beginTime != null and beginTime != \"\"'>AND order_time &gt;= #{beginTime}</if> " +
            "<if test='endTime != null and endTime != \"\"'>AND order_time &lt;= #{endTime}</if> " +
            "</script>")
    List<Orders> getOrderDetailPage(@Param("number") String number,
                                   @Param("beginTime") String beginTime,
                                   @Param("endTime") String endTime);
}
